package com.magic.smartcity.view.more.hospital

import android.graphics.Color
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import com.magic.smartcity.R
import com.magic.smartcity.beans.HospitalDepartments
import com.magic.smartcity.beans.HospitalPatientCard
import com.magic.smartcity.databinding.FragmentHospitalDepartmentsDetailBinding
import com.magic.smartcity.view.MainActivity

class HospitalDepartmentsDetailFragment : Fragment() {
    private lateinit var binding: FragmentHospitalDepartmentsDetailBinding
    //科室的ID，预约挂号时需要科室ID
    private lateinit var departmentsDetail: HospitalDepartments
    //病人详细信息
    private lateinit var patientCardDetail:HospitalPatientCard

    private lateinit var supportFragmentManager:FragmentManager
    private lateinit var normalFragment:HospitalDepartmentNormalFragment
    private val exFragment=HospitalDepartmentExFragment()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportFragmentManager = activity?.supportFragmentManager!!
        departmentsDetail = arguments?.getSerializable("departmentsDetail") as HospitalDepartments
        patientCardDetail = arguments?.getSerializable("patientCardDetail") as HospitalPatientCard
        normalFragment=HospitalDepartmentNormalFragment(departmentsDetail,patientCardDetail)
        val mainActivity = activity as MainActivity
        mainActivity.setActionBarTitle(departmentsDetail.categoryName)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentHospitalDepartmentsDetailBinding.inflate(layoutInflater)
        initView()
        return binding.root
    }

    private fun initView() {
        //初始化显示的时普通挂号
        var beginTransaction = supportFragmentManager.beginTransaction().replace(binding.frameLayoutContent.id,normalFragment)
        beginTransaction.commit()
        //普通挂号
        binding.normalDepartment.setOnClickListener{

            binding.exDepartment.setTextColor(activity?.resources?.getColor(R.color.gray)!!)
            binding.exDepartment.setBackgroundResource(R.drawable.shape_button_noclick)
            binding.normalDepartment.setTextColor(activity?.resources?.getColor(R.color.white)!!)
            binding.normalDepartment.setBackgroundResource(R.drawable.shape_button_click)
            beginTransaction = supportFragmentManager.beginTransaction()
            beginTransaction.replace(binding.frameLayoutContent.id,normalFragment,"NORMAL")
            beginTransaction.commit()
        }
        //专家挂号
        binding.exDepartment.setOnClickListener{

            binding.normalDepartment.setTextColor(activity?.resources?.getColor(R.color.gray)!!)
            binding.normalDepartment.setBackgroundResource(R.drawable.shape_button_noclick)
            binding.exDepartment.setTextColor(activity?.resources?.getColor(R.color.white)!!)
            binding.exDepartment.setBackgroundResource(R.drawable.shape_button_click)
            beginTransaction = supportFragmentManager.beginTransaction()
            beginTransaction.replace(binding.frameLayoutContent.id,exFragment,"EX")
            beginTransaction.commit()
        }


    }


}